package example.lesson04_01;

public class TestStatic {
    public static void main(String[] args) {
        Person p1 = new Person(30, "ZhangSan");
        Person p2 = new Person(40,"LiSi");
        System.out.println();
        System.out.println(p1.toString());
    }
}

class Person {
    //静态变量|类变量，记录创建的person对象数量
    public static int count;
    //静态代码块，在类加载到JVM的时侯执行，只会执行一次
    static {
        count = 0;
    }



    //非静态变量|实例对象变量
    public int age;
    public String name;

    //构造代码块，在每个构造函数执行前，先执行一次
    {
        count++;
    }


    Person(int age, String name) {

        this.age = age;
        this.name = name;
    }

    //静态方法|类方法，和对象无关，没有this
    public static void printCount(){
        System.out.println("Person count:"+count);
    }

    //非静态方法|实例方法,方法的执行需要和某个实例绑定，有this
    public String toString() {
        return "age:" + age + ", name:" + name;
    }

}
